package com.hm.shopping.auto.su;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import com.hm.base.vo.LoginSubscriberVo;
import com.hm.core.SdkConfig;

/**
 * @author shishun.wang
 * @date 2017年10月28日 上午10:37:58
 * @version 1.0
 * @describe
 */
public class BaseInterceptor extends HandlerInterceptorAdapter {

	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
		String scheme = request.getScheme();
		String serverName = request.getServerName();
		int port = request.getServerPort();
		String path = request.getContextPath();
		String basePath = scheme + "://" + serverName + ":" + port + path;
		request.setAttribute("basePath", basePath);
		Object obj = request.getSession().getAttribute(R.Session.SUBSCRIBER_SESSION);
		if (null != obj) {
			LoginSubscriberVo subscriberVo = (LoginSubscriberVo) obj;
			request.getSession().setAttribute(SdkConfig.REMOTE_CLIENT_AUTHORIZATION, subscriberVo.getToken());
		}
		request.setAttribute("userInfo", obj);

		return true;
	}
}
